From a8a1d48e4ccc545e7f50d46beb32acd2833fd474 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 26 Oct 2005 14:58:13 +0100 Subject: [PATCH] Break the write_dev function out from block into new block-common.sh, where it can also be used by block-enbd and block-nbd. Signed-off-by: Ewan Mellor --- tools/examples/Makefile | 3 +- tools/examples/block | 16 ++--------- tools/examples/block-common.sh | 51 ++++++++++++++++++++++++++++++++++ tools/examples/block-enbd | 14 +++------- tools/examples/block-nbd | 18 ++++-------- 5 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 tools/examples/block-common.sh diff --git a/tools/examples/Makefile b/tools/examples/Makefile index 2af687e535..54164235b4 100644 --- a/tools/examples/Makefile +++ b/tools/examples/Makefile @@ -24,8 +24,9 @@ XEN_SCRIPTS = network-bridge vif-bridge XEN_SCRIPTS += network-route vif-route XEN_SCRIPTS += network-nat vif-nat XEN_SCRIPTS += block -XEN_SCRIPTS += block-enbd +XEN_SCRIPTS += block-enbd block-nbd XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh +XEN_SCRIPTS += block-common.sh XEN_HOTPLUG_DIR = /etc/hotplug XEN_HOTPLUG_SCRIPTS = xen-backend.agent diff --git a/tools/examples/block b/tools/examples/block index 2e383bb3a6..c5b6b6c215 100644 --- a/tools/examples/block +++ b/tools/examples/block @@ -1,7 +1,7 @@ #!/bin/sh dir=$(dirname "$0") -. "$dir/xen-hotplug-common.sh" +. "$dir/block-common.sh" expand_dev() { local dev @@ -16,21 +16,9 @@ expand_dev() { echo -n $dev } -write_dev() { - local major - local minor - local pdev - - major=$(stat -L -c %t "$1") - minor=$(stat -L -c %T "$1") - pdev=$(printf "0x%02x%02x" 0x$major 0x$minor) - xenstore_write "$XENBUS_PATH"/physical-device $pdev \ - "$XENBUS_PATH"/node $1 -} - t=$(xenstore_read "$XENBUS_PATH"/type || true) -case $1 in +case "$command" in bind) p=$(xenstore_read "$XENBUS_PATH"/params) case $t in diff --git a/tools/examples/block-common.sh b/tools/examples/block-common.sh new file mode 100644 index 0000000000..1d20550a9d --- /dev/null +++ b/tools/examples/block-common.sh @@ -0,0 +1,51 @@ +# +# Copyright (c) 2005 XenSource Ltd. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + + +dir=$(dirname "$0") +. "$dir/xen-hotplug-common.sh" + +command="$1" + +if [ "$command" != "bind" ] && [ "$command" != "unbind" ] +then + log err "Invalid command: $command" + exit 1 +fi + + +XENBUS_PATH="${XENBUS_PATH:?}" + + +## +# Write physical-device = 0xMMmm and node = device to the store, where MM +# and mm are the major and minor numbers of device. +# +# @param device The device from which major and minor numbers are read, which +# will be written into the store. +# +write_dev() { + local major + local minor + local pdev + + major=$(stat -L -c %t "$1") + minor=$(stat -L -c %T "$1") + pdev=$(printf "0x%02x%02x" "0x$major" "0x$minor") + xenstore_write "$XENBUS_PATH"/physical-device "$pdev" \ + "$XENBUS_PATH"/node "$1" +} diff --git a/tools/examples/block-enbd b/tools/examples/block-enbd index c86068d817..c58adb595d 100755 --- a/tools/examples/block-enbd +++ b/tools/examples/block-enbd @@ -2,25 +2,19 @@ # Usage: block-enbd [bind server ctl_port |unbind node] # -# The file argument to the bind command is the file we are to bind to a -# loop device. -# # The node argument to unbind is the name of the device node we are to # unbind. # # This assumes you're running a correctly configured server at the other end! -set -e +dir=$(dirname "$0") +. "$dir/block-common.sh" -case $1 in +case "$command" in bind) for dev in /dev/nd*; do if nbd-client $2:$3 $dev; then - major=$(stat -L -c %t "$dev") - minor=$(stat -L -c %T "$dev") - pdev=$(printf "0x%02x%02x" 0x$major 0x$minor) - xenstore-write "$XENBUS_PATH"/physical-device $pdev \ - "$XENBUS_PATH"/node $dev + write_dev $dev exit 0 fi done diff --git a/tools/examples/block-nbd b/tools/examples/block-nbd index 06f9f6875e..142a403c0f 100644 --- a/tools/examples/block-nbd +++ b/tools/examples/block-nbd @@ -1,28 +1,20 @@ #!/bin/sh -# Usage: block-enbd [bind server ctl_port |unbind node] -# -# The file argument to the bind command is the file we are to bind to a -# loop device. +# Usage: block-nbd [bind server ctl_port |unbind node] # # The node argument to unbind is the name of the device node we are to # unbind. # # This assumes you're running a correctly configured server at the other end! -set -e - -#echo "block-enbd: $@" | logger -t xen +dir=$(dirname "$0") +. "$dir/block-common.sh" -case $1 in +case "$command" in bind) for dev in /dev/nbd*; do if nbd-client $2 $3 $dev; then - major=$(stat -L -c %t "$dev") - minor=$(stat -L -c %T "$dev") - pdev=$(printf "0x%02x%02x" 0x$major 0x$minor) - xenstore-write "$XENBUS_PATH"/physical-device $pdev \ - "$XENBUS_PATH"/node $dev + write_dev $dev exit 0 fi done -- 2.30.2